package com.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.mapper.Pms_Spu_Images_Mapper;
import com.shop.pojo.pms.Pms_Spu_Images;
import com.shop.service.Pms_Spu_Images_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class Pms_Spu_Images_ServiceImpl extends ServiceImpl<Pms_Spu_Images_Mapper,Pms_Spu_Images> implements Pms_Spu_Images_Service  {
    /*
     * @Description 首先通过strean进行转换，然后批量插入数据
     * @param id 传来的spuID
     * @param images 多个img
     * @return void
     * @author liusupeng
     * @date 2020/10/30 19:36
     */
    @Override
    public void saveImages(Long id, List<String> images) {

         if(images==null||images.size()==0){

         }else{
             List<Pms_Spu_Images> collect = images.stream().map(img -> {
                 Pms_Spu_Images pms_spu_images = new Pms_Spu_Images();
                 pms_spu_images.setSpu_id(id);
                 pms_spu_images.setImg_url(img);
                 return pms_spu_images;
             }).collect(Collectors.toList());
             this.saveBatch(collect);//批量插入

         }
    }
}
